package be.colwri.server;

import java.util.Vector;

import be.colwri.client.AddCommand;
import be.colwri.client.Command;

public class CommandProcessor {
	
	Vector<Command> commandvec = new Vector<Command>();
 //   Command[] commandar; 
    String result = ""; 


    public String getResult() {
		return result;
	}
    
    

	public void setResult(String result) {
		this.result = result;
	}

	/**
     * @pre com != null
     * @param com
     * 
     * = HERBEREKENING wordt gedaan vanaf Command die
     */
 public synchronized void addCommand (Command com, int from)
 {
	 commandvec.add(com);
	 
 }
 
 public synchronized int addCommands(Vector<Command> commands, int from)
 {
	
	commandvec.addAll(commands);

	int a,i;
	
	
	/**De vectoren die aangepast moeten worden zijn deze  **/
	for (i = commandvec.size() - commands.size(); i<commandvec.size(); i++) {
		Command cm = commandvec.get(i);
		for (a = from; a < commandvec.size() - commands.size(); a++) {
			System.out.println(a+" " + i + " ");
			(commandvec.get(a)).doorstuurCommand(cm);
		}	
		setResult(cm.execute(getResult()));
		System.out.println(getResult());
	}
	
	
	/*for (i=from; i<commandvec.size(); i++) {
     Command cm = commandvec.get(i);
     for (a = from; a < commandvec.size() - commands.size(); a++) { //Because Calculation should not take into account OWN records
    	 
    	 if (a != i) {cm.recalculateCommand(commandvec.get(a));}
    	 
     }*/
     //Now executing ...
     
	
	return commandvec.size();
 }
 
 
 public int getSize() {
	 return commandvec.size();
 }
 
 
 
 
 
 
 public Command getCommand (int number) {
	 return commandvec.get(number);
 }
 
 
 
}
